let clickRecord = (function () {
    let dir = window.location.pathname;
    dir = dir.substring(0, dir.lastIndexOf("/"));
    if (dir.indexOf("html") == -1) {
        dir = dir.substring(0, dir.lastIndexOf("view"));
    } else {
        dir = dir.substring(0, dir.lastIndexOf("html"));
    }

    /**
     * 加载数据
     * @param action
     */
    let loadData = function (action, id, recall) {
        $.get(dir + "/view/click_record.php?type=load&action=" + action + "&id=" + id,
            function (data) {
                if (recall) {
                    recall(data);
                }
            }
        );
    };
    /**
     * 记录数据
     * @param action
     * @param id
     */
    let recordData = function (action, id) {
        let url = dir + "/view/click_record.php?type=record&action=" + action + "&id=" + id;
        $.get(url, function (data) {
        });
    };
    return {
        /**
         * 加载网站访问次数
         */
        indexRecord: function (id, recall) {
            return loadData("systemconfig", recall);
        },
        /**
         * 记录网站点击次数
         */
        indexClick: function (id) {
            recordData("systemconfig", id);
        },
        /**
         * 加载单页面点击次数
         * @param id
         */
        pageRecord: function (id, recall) {
            return loadData("pages", id, recall);
        },
        /**
         * 单页面点击
         * @param id
         */
        pageClick: function (id) {
            recordData("pages", id);
        },
        /**
         * 加载新闻页点击次数
         * @param id
         */
        newsRecord: function (id, recall) {
            return loadData("news", id, recall);
        },
        /**
         * 新闻页点击
         * @param id
         */
        newsClick: function (id) {
            recordData("news", id);
        },
        /**
         * 加载产品页点击次数
         * @param id
         */
        productRecord: function (id, recall) {
            return loadData("product", id, recall);
        },
        /**
         * 产品点击
         * @param id
         */
        productClick: function (id) {
            recordData("product", id);
        },
        /**
         * 加载招聘点击次数
         * @param id
         */
        jobRecord: function (id, recall) {
            return loadData("job", id, recall);
        },
        /**
         * 工作点击
         * @param id
         */
        jobClick: function (id) {
            recordData("job", id);
        }
    }
})();